//
//  ShaiorderDetailViewController.m
//  danpin
//
//  Created by chuangjia on 2/9/15.
//  Copyright (c) 2015 chuangjia. All rights reserved.
//

#import "ShaiorderDetailViewController.h"

#import "CellConfig.h"
#import "GoodClassViewController.h"
#import "GoodBrandViewController.h"
#import "TaoBaoViewController.h"
#import "CommentViewController.h"
#import "UserLoginVC.h"
#import "BaseModel.h"
#import "ZToastManager.h"
#import "CommentHeaderSectionView.h"
#import "BaiChuanShare.h"
#import "OtherUserCenterVC.h"
#import "ShaiDanVC.h"
#import "ZPlatformShare.h"
#import "ZShare.h"
#import "GoodConfig.h"
#import "AppDelegate.h"
#import "ZFooterView.h"
#import "NiubiSearchVC.h"
#import "ZToolControl.h"
#import "CommentKeyBord.h"
#import "WebViewController.h"
@interface ShaiorderDetailViewController ()<UITableViewDataSource,UITableViewDelegate,CommentKeyBordDelegate>
{
    
}
@property(nonatomic,strong)UITableView *tbView;
@property(nonatomic,strong)NSString *currentPid;
@property(nonatomic,strong)NSMutableArray *tagArray;
@property(nonatomic,strong)NSMutableArray *soldArray;
@property(nonatomic,strong)NSMutableArray *sectionsArray;
@property(nonatomic,strong)NSMutableArray *commentArray;
@property(nonatomic,assign)BOOL isLoadFinished;
@property(nonatomic,assign)BOOL isRequesting;
@property(nonatomic,assign)int  currentPage;
@property(nonatomic,assign)BOOL isShaiDan;
//
@property (nonatomic,strong)NSMutableDictionary *askingDictionary;
@property (nonatomic,strong)NSMutableDictionary *recommendDictionary;
@property (nonatomic,strong)NSMutableDictionary *shaidanDictionary;
#ifdef LCB_GET_PRICE
@property (nonatomic,strong)NSMutableDictionary *soldInfoDictionary;
#endif
@property(nonatomic,strong)NSMutableArray *loveListArray; //喜爱

@property(nonatomic,strong)NSString *catName;
@property(nonatomic,strong)UIButton *LikeBtn;

//
@property(nonatomic,strong)NSMutableArray *nodeSectionArray;

@property(nonatomic,strong)ZToolControl *footToolsView;
@end

@implementation ShaiorderDetailViewController
@synthesize type=_type;
@synthesize dictionary=_dictionary;
@synthesize photo_id=_photo_id;
@synthesize footToolsView=_footToolsView;
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [UMengShare event:CK_SHAIORDERDETAIL acc:[_photo_id integerValue]];

    self.view.backgroundColor =[UIColor whiteColor];
    
    //
    self.isDetail = YES;
    
    //
    if (!_nodeSectionArray) {
        _nodeSectionArray =[[NSMutableArray alloc] init];
    }
    //购买链接
    if (!_soldArray) {
        _soldArray=[[NSMutableArray alloc] init];
    }
    //喜欢
    if (!_loveListArray) {
        _loveListArray =[[NSMutableArray alloc] init];
    }
    //求购信息
    if(!_askingDictionary)
    {
        _askingDictionary=[[NSMutableDictionary alloc] init];
    }
    //相关推荐
    if (!_shaidanDictionary) {
        _shaidanDictionary =[[NSMutableDictionary alloc] init];
    }
    //相关推荐
    if (!_recommendDictionary) {
        _recommendDictionary =[[NSMutableDictionary alloc] init];
    }
    //评论
    if(!_commentArray)
    {
        _commentArray=[[NSMutableArray alloc] init];
    }
    
#ifdef LCB_GET_PRICE
    if (!_soldInfoDictionary) {
        _soldInfoDictionary =[[NSMutableDictionary alloc] init];
    }
#endif
    self.isLoadFinished =NO;
    self.isRequesting =NO;
    self.currentPage=0;
    //
    [self initUI];
    [self notificationManager];
    [self initFootView];
    int like =[[self.dictionary objectForKey:@"like"] intValue];
    if (like==1) {
        self.footToolsView.isLove = YES;
    }else{
        self.footToolsView.isLove = NO;
    }
    
    [ZShare showAnimationView:self.view center:CGPointZero];
    self.currentPage=0;
    [self getGoodDataWithPid:self.photo_id];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if (self.type==0 || self.type==3) {
        self.navigationController.enableBackGesture=NO;
    }else{
        self.navigationController.enableBackGesture=YES;
    }
    
}
-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    DLog(@"%s", __PRETTY_FUNCTION__);
    
}
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [_sectionsArray removeAllObjects];
    _sectionsArray=nil;
    [_tagArray removeAllObjects];
    _tagArray =nil;
    [_soldArray removeAllObjects];
    _soldArray =nil;
    _askingDictionary=nil;
    _recommendDictionary=nil;
    
    self.tbView =nil;
    self.shaidanDictionary=nil;
    if (_nodeSectionArray) {
        [_nodeSectionArray removeAllObjects];
        _nodeSectionArray=nil;
    }
#ifdef LCB_GET_PRICE
    self.soldInfoDictionary=nil;
#endif
    if (_footToolsView) {
        [_footToolsView removeFromSuperview];
        _footToolsView=nil;
    }
    [CommentKeyBord commentKeyboard].mDelegate=nil;
    [[CommentKeyBord commentKeyboard].mTextView resignFirstResponder];
    [[CommentKeyBord commentKeyboard].mTextView removeFromSuperview];
    [CommentKeyBord commentKeyboard].mTextView=nil;
    DLog(@"%s", __PRETTY_FUNCTION__);
}

-(void)clickNavEvent:(id)sender
{
    UIButton *btn =(UIButton *)sender;
    switch (btn.tag) {
        case 0:
        {
            self.navigationController.enableBackGesture=YES;
            if (self.type==0) {
                [self.navigationController popToRootViewControllerAnimated:YES];
            }else
            {
                
                [self.navigationController popViewControllerAnimated:YES];
            }
        }
            
            break;
        case 2:
        {
            [self shareAction];
        }
            break;
        case 3:
        {
            [self likeAction];
        }
            break;
        case 4:
        {
            [self shaidanAction];
        }
            break;
        default:
            break;
    }
}

//
-(void)initUI
{
    _tbView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.navHeight, self.view.frame.size.width, self.view.frame.size.height-self.navHeight-BOTTOM_TOOLBAR_HEIGHT) style:UITableViewStyleGrouped];
    _tbView.delegate = self;
    _tbView.dataSource = self;
    _tbView.showsVerticalScrollIndicator = NO;
    _tbView.backgroundColor = [UIColor clearColor];
    _tbView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_tbView];
    // setup infinite scrolling
    __weak typeof (self) wSelf = self;
    [self.tbView addInfiniteScrollingWithActionHandler:^{
        if (self.isRequesting==YES) {
            //停止菊花
            [wSelf.tbView.infiniteScrollingView stopAnimating];
            return ;
        }
        if (wSelf.isLoadFinished) {
            //停止菊花
            [wSelf.tbView.infiniteScrollingView stopAnimating];
            return;
        }
        [wSelf.tbView.infiniteScrollingView startAnimating];
        if ([wSelf.commentArray count]>0) {
            wSelf.currentPage =(int) [wSelf.commentArray count];
        }
        [wSelf loadData];
        [wSelf.tbView.infiniteScrollingView stopAnimating];
        
    }];
    
}

#pragma mark - tableview
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _nodeSectionArray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSString *sectionTitle =[self.nodeSectionArray objectAtIndex:section];
    
    if ([sectionTitle isEqualToString:@"goodTitleCell"])
    {
        return 1;
    }else
    if ([sectionTitle isEqualToString:@"userinfo"])
    {
        return 1;
    }else if ([sectionTitle isEqualToString:@"photoCell"])
    {
        return self.soldArray.count;
        
    }else if ([sectionTitle isEqualToString:@"lovecell"])
    {
        return 1;
    }else if ([sectionTitle isEqualToString:@"detailCell"])
    {
        return 1;
    }else if ([sectionTitle isEqualToString:@"purchasecell"])
    {
        if ([self.askingDictionary count]>0) {
            
            NSMutableArray *keyArry =[NSMutableArray arrayWithArray:[self.askingDictionary allKeys]];
            if ([keyArry containsObject:@"99999999"]) {
                [keyArry removeObject:@"99999999"];
            }
            return [keyArry count];
        }
        return 0;
    }else if ([sectionTitle isEqualToString:@"recommendcell"])
    {
        return 1;
    }else if ([sectionTitle isEqualToString:@"commentcell"])
    {
        return self.commentArray.count;
    }
    
    return 0;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    NSString *sectionTitle =[self.nodeSectionArray objectAtIndex:section];
    
    if ([sectionTitle isEqualToString:@"goodTitleCell"])
    {
        return 0.01;
    }else  if ([sectionTitle isEqualToString:@"userinfo"])
    {
        return PHOTO_TIME_PADDING;
    }else  if ([sectionTitle isEqualToString:@"photoCell"])
    {
        return PHOTO_TIME_PADDING;
    }else if ([sectionTitle isEqualToString:@"lovecell"])
    {
        return PHOTO_FRAME_WIDTH*3;
    }else if ([sectionTitle isEqualToString:@"detailCell"])
    {
        return PHOTO_FRAME_WIDTH*3;
    }else if ([sectionTitle isEqualToString:@"purchasecell"])
    {
        return PHOTO_FRAME_WIDTH*3;
    }else if ([sectionTitle isEqualToString:@"recommendcell"])
    {
        return PHOTO_FRAME_WIDTH*3;
    }else if ([sectionTitle isEqualToString:@"commentcell"])
    {
        return PHOTO_FRAME_WIDTH*3;
    }
    return 0.01;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
//    NSString *sectionTitle =[self.nodeSectionArray objectAtIndex:section];

    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *sectionTitle =[self.nodeSectionArray objectAtIndex:indexPath.section];
    
    if ([sectionTitle isEqualToString:@"goodTitleCell"])
    {
        return [GoodTitleCell returnCellHeight:self.dictionary];
    }else  if ([sectionTitle isEqualToString:@"userinfo"])
    {
        return [UserCell returnCellHeight:self.dictionary];
    }else  if ([sectionTitle isEqualToString:@"photoCell"])
    {
        NSDictionary *dict = [self.soldArray objectAtIndex:indexPath.row];
        return [ShaiorderPhotoCell returnCellHeight:dict];
        
    }else if ([sectionTitle isEqualToString:@"lovecell"])
    {
        return [GoodLikeCell returnCellHeight:self.loveListArray];
    }else if ([sectionTitle isEqualToString:@"detailCell"])
    {
        return [GoodsDetailCell returnCellHeight:self.shaidanDictionary];
    }else if ([sectionTitle isEqualToString:@"purchasecell"])
    {
        if ([self.askingDictionary count]>0) {
            NSMutableArray *numArray = [NSMutableArray arrayWithArray:[self.askingDictionary allKeys]];
            if ([numArray containsObject:@"99999999"]) {
                [numArray removeObject:@"99999999"];
            }
            NSString* kv =[numArray objectAtIndex:indexPath.row];
            NSDictionary* dict =[self.askingDictionary objectForKey:kv];
            return [GoodQiuCell returnCellHeight:dict];
        }
        
        return 1;
    }else if ([sectionTitle isEqualToString:@"recommendcell"])
    {
        return [GoodRecommedCell returnCellHeight:self.recommendDictionary];
    }else if ([sectionTitle isEqualToString:@"commentcell"])
    {
        NSDictionary *dict = [self.commentArray objectAtIndex:indexPath.row];
        return [GoodCommentCell returnCellHeight:dict];
    }
    return 50;
    
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *sectionView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, _tbView.frame.size.width, PHOTO_FRAME_WIDTH*2)];
    sectionView.backgroundColor =UIColorFromRGB(0xf9f9f9);
    
    NSString *sectionTitle =[self.nodeSectionArray objectAtIndex:section];
    if ([sectionTitle isEqualToString:@"goodTitleCell"])
    {
        return nil;
    }else if ([sectionTitle isEqualToString:@"userinfo"])
    {
        return nil;
    }else if ([sectionTitle isEqualToString:@"photoCell"])
    {
        return nil;
    }else if ([sectionTitle isEqualToString:@"lovecell"])
    {
        UILabel *tagValue =[[UILabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH,0, _tbView.frame.size.width, PHOTO_FRAME_WIDTH*3)];
        tagValue.backgroundColor = [UIColor clearColor];
        tagValue.textColor = UIColorFromRGB(0x999999);
        tagValue.textAlignment = NSTextAlignmentLeft;
        tagValue.font = FONT(14);
        tagValue.text =@"喜欢";
        [sectionView addSubview:tagValue];
        tagValue=nil;
        return sectionView;
    }else if ([sectionTitle isEqualToString:@"detailCell"])
    {
        UILabel *tagValue =[[UILabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH,0, _tbView.frame.size.width, PHOTO_FRAME_WIDTH*3)];
        tagValue.backgroundColor = [UIColor clearColor];
        tagValue.textColor = UIColorFromRGB(0x999999);
        tagValue.textAlignment = NSTextAlignmentLeft;
        tagValue.font = FONT(14);
        tagValue.text =@"商品信息";
        [sectionView addSubview:tagValue];
        tagValue=nil;
        return sectionView;
    }else if ([sectionTitle isEqualToString:@"purchasecell"])
    {
        UILabel *tagValue =[[UILabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH,0, _tbView.frame.size.width, PHOTO_FRAME_WIDTH*3)];
        tagValue.backgroundColor = [UIColor clearColor];
        tagValue.textColor = UIColorFromRGB(0x999999);
        tagValue.textAlignment = NSTextAlignmentLeft;
        tagValue.font = FONT(14);
        tagValue.text =@"求购信息";
        [sectionView addSubview:tagValue];
        tagValue=nil;
        return sectionView;
    }else if ([sectionTitle isEqualToString:@"recommendcell"])
    {
        UILabel *tagValue =[[UILabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH,0, _tbView.frame.size.width, PHOTO_FRAME_WIDTH*3)];
        tagValue.backgroundColor = [UIColor clearColor];
        tagValue.textColor = UIColorFromRGB(0x999999);
        tagValue.textAlignment = NSTextAlignmentLeft;
        tagValue.font = FONT(14);
        tagValue.text =@"相关推荐";
        [sectionView addSubview:tagValue];
        tagValue=nil;
        if(self.recommendDictionary.count>6)
//        {
//            UIButton *more = [UIButton buttonWithType:UIButtonTypeCustom];
//            more.frame = CGRectMake(_tbView.frame.size.width-60, 0, 60, PHOTO_FRAME_WIDTH*3);
//            more.backgroundColor =[UIColor clearColor];
//            more.titleLabel.font = FONT(14);
//            [more setTitleColor:UIColorFromRGB(0x285790) forState:UIControlStateNormal];
//            [more setTitle:@"更多" forState:UIControlStateNormal];
//            [more addTarget:self action:@selector(recommedMoreAction) forControlEvents:UIControlEventTouchUpInside];
//            [sectionView addSubview:more];
//            more=nil;
//        }
       
        return sectionView;
    }else if ([sectionTitle isEqualToString:@"commentcell"])
    {
        UILabel *tagValue =[[UILabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH,0, _tbView.frame.size.width, PHOTO_FRAME_WIDTH*3)];
        tagValue.backgroundColor = [UIColor clearColor];
        tagValue.textColor = UIColorFromRGB(0x999999);
        tagValue.textAlignment = NSTextAlignmentLeft;
        tagValue.font = FONT(14);
        tagValue.text =@"点评";
        [sectionView addSubview:tagValue];
        tagValue=nil;
//        UIButton *more = [UIButton buttonWithType:UIButtonTypeCustom];
//        more.frame = CGRectMake(_tbView.frame.size.width-100, 0, 100, PHOTO_FRAME_WIDTH*3);
//        more.backgroundColor =[UIColor clearColor];
//        more.titleLabel.font = FONT(14);
//        [more setTitleColor:UIColorFromRGB(0x285790) forState:UIControlStateNormal];
//        [more setTitle:@"我来点评" forState:UIControlStateNormal];
//        [more addTarget:self action:@selector(commentMoreAction) forControlEvents:UIControlEventTouchUpInside];
//        [sectionView addSubview:more];
//        more=nil;
        return sectionView;
    }
    return sectionView;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = (UITableViewCell*)[tableView  dequeueReusableCellWithIdentifier:@""];
    
    NSString *sectionTitle =[self.nodeSectionArray objectAtIndex:indexPath.section];
    if ([sectionTitle isEqualToString:@"goodTitleCell"])
    {
        GoodTitleCell *cell = (GoodTitleCell*)[tableView  dequeueReusableCellWithIdentifier:@""];
        if(cell == nil)
        {
            cell = [[GoodTitleCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
            cell.backgroundColor=[UIColor clearColor];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            _tbView.separatorStyle = UITableViewCellSeparatorStyleNone;
            __weak typeof (self) wSelf = self;
            [cell setCallBack:^(BEventType t, UIView *v,id obj,id key,NSIndexPath *indexPath) {
                [wSelf cellAction:t views:v obj:obj key:key indexPath:indexPath];
            }];
        }
        [cell showInfo:self.dictionary indexPath:indexPath];
        return cell;
        
    }else if ([sectionTitle isEqualToString:@"userinfo"])
    {
        UserCell *cell = (UserCell*)[tableView  dequeueReusableCellWithIdentifier:@""];
        if(cell == nil)
        {
            cell = [[UserCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
            cell.backgroundColor=[UIColor clearColor];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            _tbView.separatorStyle = UITableViewCellSeparatorStyleNone;
            __weak typeof (self) wSelf = self;
            [cell setCallBack:^(BEventType t, UIView *v,id obj,id key,NSIndexPath *indexPath) {
                [wSelf cellAction:t views:v obj:obj key:key indexPath:indexPath];
            }];
        }
        [cell showInfo:self.dictionary key:@"userinfo" indexPath:indexPath];
        return cell;
    }else if ([sectionTitle isEqualToString:@"photoCell"])
    {
        ShaiorderPhotoCell *cell = (ShaiorderPhotoCell*)[tableView  dequeueReusableCellWithIdentifier:@""];
        if(cell == nil)
        {
            cell = [[ShaiorderPhotoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
            cell.backgroundColor=[UIColor clearColor];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            _tbView.separatorStyle = UITableViewCellSeparatorStyleNone;
            __weak typeof (self) wSelf = self;
            [cell setCallBack:^(BEventType t, UIView *v,id obj,id key,NSIndexPath *indexPath) {
                [wSelf cellAction:t views:v obj:obj key:key indexPath:indexPath];
            }];
        }
        NSDictionary *pic =[self.soldArray objectAtIndex:indexPath.row];
        [cell showInfo:pic indexPath:indexPath];
        return cell;
    }else if ([sectionTitle isEqualToString:@"lovecell"])
    {
        GoodLikeCell *cell = (GoodLikeCell*)[tableView  dequeueReusableCellWithIdentifier:@""];
        if(cell == nil)
        {
            cell = [[GoodLikeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
            cell.backgroundColor=[UIColor clearColor];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            _tbView.separatorStyle = UITableViewCellSeparatorStyleNone;
            __weak typeof (self) wSelf = self;
            [cell setCallBack:^(BEventType t, UIView *v,id obj,id key,NSIndexPath *indexPath) {
                [wSelf cellAction:t views:v obj:obj key:key indexPath:indexPath];
            }];
        }
        [cell showInfo:self.loveListArray  indexPath:indexPath];
        return cell;
    }else if ([sectionTitle isEqualToString:@"detailCell"])
    {
        GoodsDetailCell *cell = (GoodsDetailCell*)[tableView  dequeueReusableCellWithIdentifier:@""];
        if(cell == nil)
        {
            cell = [[GoodsDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
            cell.backgroundColor=[UIColor clearColor];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            _tbView.separatorStyle = UITableViewCellSeparatorStyleNone;
            __weak typeof (self) wSelf = self;
            [cell setCallBack:^(BEventType t, UIView *v,id obj,id key,NSIndexPath *indexPath) {
                [wSelf cellAction:t views:v obj:obj key:key indexPath:indexPath];
            }];
        }
        [cell showInfo:self.shaidanDictionary key:@"detailCell" indexPath:indexPath];
        return cell;
    }else if ([sectionTitle isEqualToString:@"purchasecell"])
    {
        if ([self.askingDictionary count]>0)
        {
            GoodQiuCell *cell = (GoodQiuCell*)[tableView  dequeueReusableCellWithIdentifier:@""];
            if(cell == nil)
            {
                cell = [[GoodQiuCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
                cell.backgroundColor=[UIColor clearColor];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                _tbView.separatorStyle = UITableViewCellSeparatorStyleNone;
                __weak typeof (self) wSelf = self;
                [cell setCallBack:^(BEventType t, UIView *v,id obj,id key,NSIndexPath *indexPath) {
                    [wSelf cellAction:t views:v obj:obj key:key indexPath:indexPath];
                }];
                
            }
            NSMutableArray *numArray = [NSMutableArray arrayWithArray:[self.askingDictionary allKeys]];
            
            if ([numArray containsObject:@"99999999"]) {
                [numArray removeObject:@"99999999"];
            }
            NSString* kv =[numArray objectAtIndex:indexPath.row];
            NSDictionary *dict =[self.askingDictionary objectForKey:kv];
            [cell showInfo:dict key:@"purchasecell" indexPath:indexPath];
            
            return cell;
        }
        
        
        return cell;
    }else if ([sectionTitle isEqualToString:@"recommendcell"])
    {
        
        GoodRecommedCell *cell = (GoodRecommedCell*)[tableView  dequeueReusableCellWithIdentifier:@""];
        if(cell == nil)
        {
            cell = [[GoodRecommedCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
            cell.backgroundColor=[UIColor clearColor];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            _tbView.separatorStyle = UITableViewCellSeparatorStyleNone;
            __weak typeof (self) wSelf = self;
            [cell setCallBack:^(BEventType t, UIView *v,id obj,id key,NSIndexPath *indexPath) {
                [wSelf cellAction:t views:v obj:obj key:key indexPath:indexPath];
            }];
        }
        [cell showInfo:self.recommendDictionary  indexPath:indexPath];
        
        return cell;
    }else if ([sectionTitle isEqualToString:@"commentcell"])
    {
        GoodCommentCell *cell = (GoodCommentCell*)[tableView  dequeueReusableCellWithIdentifier:@""];
        if(cell == nil)
        {
            cell = [[GoodCommentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
            cell.backgroundColor=[UIColor clearColor];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            _tbView.separatorStyle = UITableViewCellSeparatorStyleNone;
            __weak typeof (self) wSelf = self;
            [cell setCallBack:^(BEventType t, UIView *v,id obj,id key,NSIndexPath *indexPath) {
                [wSelf cellAction:t views:v obj:obj key:key indexPath:indexPath];
            }];
        }
        if (indexPath.row>=[self.commentArray count]) {
            return cell;
        }
        NSDictionary *dict =[self.commentArray objectAtIndex:indexPath.row];
        [cell showInfo:dict key:@"commentcell" indexPath:indexPath];
        return cell;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSString *sectionTitle =[self.nodeSectionArray objectAtIndex:indexPath.section];
    
    if ([sectionTitle isEqualToString:@"detailCell"])
    {
        GoodViewController *good =[[GoodViewController alloc] init];
        good.dictionary = self.shaidanDictionary;
        good.type=-1;
        good.photo_id = [self.shaidanDictionary objectForKey:@"photo_id"];
        [self.navigationController pushViewController:good animated:YES];
        good=nil;
        
    }else if ([sectionTitle isEqualToString:@"userinfo"])
    {
        NSDictionary *obj =[self.dictionary objectForKey:@"user"];
        OtherUserCenterVC *user =[[OtherUserCenterVC alloc] init];
        NSMutableDictionary *dict =[NSMutableDictionary dictionary];
        [dict setValue:[[NSString stringWithFormat:@"%@",[obj objectForKey:@"largeFace"]] replaceNullString] forKey:@"largeFace"];
        [dict setValue:[[NSString stringWithFormat:@"%@",[obj objectForKey:@"user_id"]] replaceNullString] forKey:@"user_id"];
        [dict setValue:[[NSString stringWithFormat:@"%@",[obj objectForKey:@"nick_name"]] replaceNullString] forKey:@"nick_name"];
        user.userDictionary=dict;
        [self.navigationController pushViewController:user animated:YES];
    }else  if ([sectionTitle isEqualToString:@"commentcell"])
    {
        NSDictionary *dict =[self.commentArray objectAtIndex:indexPath.row];
        CommentViewController *comm =[[CommentViewController alloc] init];
        comm.photo_id =self.photo_id;
        comm.fromType =@"2";
        comm.dictionary =dict;
        [self.navigationController pushViewController:comm animated:YES];
    }
}
-(void)cellAction:(BEventType)type views:(UIView *)v obj:(id)obj key:(id)key indexPath:(NSIndexPath *)indexPath
{
    switch (type) {
        case BEventType_category:
        {
            
            GoodClassViewController *cate =[[GoodClassViewController alloc] init];
            cate.cateName =[NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"cat2"]];
            cate.cateCid =[NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"cat2_id"]];
            cate.cateTag =@"";
            [self.navigationController pushViewController:cate animated:YES];
            cate=nil;
        }
            break;
        case BEventType_categoryTag:
        {
            GoodClassViewController *cate =[[GoodClassViewController alloc] init];
            cate.cateName =[NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"cat2"]];
            cate.cateCid =[NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"cat2_id"]];
            cate.cateTag =[NSString stringWithFormat:@"%@",key];
            [self.navigationController pushViewController:cate animated:YES];
        }
            break;
        case BEventType_brand:
        {
            GoodBrandViewController *brand =[[GoodBrandViewController alloc] init];
            brand.brandName =[NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"brand"]];
            brand.brandId =[NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"brand_id"]];
            brand.cId =[NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"cat2_id"]];
            [self.navigationController pushViewController:brand animated:YES];
        }
            break;
        case BEventType_good:
        {
            int is_shaidan =[[obj objectForKey:@"is_shaidan"] intValue];
            if (is_shaidan==1)
            {
                ShaiorderDetailViewController *good =[[ShaiorderDetailViewController alloc] init];
                good.type =-1;
                good.dictionary = obj;
                good.photo_id = [NSString stringWithFormat:@"%@",[obj objectForKey:@"photo_id"]];
                [self.navigationController pushViewController:good animated:YES];
                good=nil;
            }else if (is_shaidan==20) {
                WebViewController *web =[[WebViewController alloc] init];
                [self.navigationController pushViewController:web animated:YES];
                web=nil;
                
            } else{
                GoodViewController *good =[[GoodViewController alloc] init];
                good.type =-1;
                good.dictionary =obj;
                good.photo_id = [NSString stringWithFormat:@"%@",[obj objectForKey:@"photo_id"]];
                [self.navigationController pushViewController:good animated:YES];
                good =nil;
            }
        }
            break;
        case BEventType_comment:
        {
            NSString *pid =[NSString stringWithFormat:@"%@",[obj objectForKey:@"photo_id"]];
            CommentViewController *comm =[[CommentViewController alloc] init];
            comm.photo_id =pid;
            comm.fromType =@"1";
            comm.dictionary =obj;
            [self.navigationController pushViewController:comm animated:YES];
        }
            break;
        case BEventType_like:
        {
            NSString *pid =[NSString stringWithFormat:@"%@",[obj objectForKey:@"photo_id"]];
            if ([self isLogin]) {
                [self likeWithPid:pid key:key indexPath:indexPath];
            }
        }
            break;
      
        case BEventType_ding:
        {
            NSString *cmid =[NSString stringWithFormat:@"%@",[obj objectForKey:@"comment_id"]];
            if ([self isLogin]) {
                [self postTop:cmid type:1];
            }
            
        }
            break;
        case BEventType_cai:
        {
            NSString *cmid =[NSString stringWithFormat:@"%@",[obj objectForKey:@"comment_id"]];
            if ([self isLogin]) {
                [self postTop:cmid type:0];
            }
        }break;
        case BEventType_sunUser:
        {
            OtherUserCenterVC *user =[[OtherUserCenterVC alloc] init];
            NSMutableDictionary *dict =[NSMutableDictionary dictionary];
            [dict setValue:[[NSString stringWithFormat:@"%@",[obj objectForKey:@"largeFace"]] replaceNullString] forKey:@"largeFace"];
            [dict setValue:[[NSString stringWithFormat:@"%@",[obj objectForKey:@"user_id"]] replaceNullString] forKey:@"user_id"];
            [dict setValue:[[NSString stringWithFormat:@"%@",[obj objectForKey:@"nick_name"]] replaceNullString] forKey:@"nick_name"];
            user.userDictionary=dict;
            [self.navigationController pushViewController:user animated:YES];
        }
            break;
        default:
            break;
    }
}
//查看更多相关推荐
-(void)recommedMoreAction
{
    NSMutableArray *numArray = [NSMutableArray arrayWithArray:[self.recommendDictionary allKeys]];
    if ([numArray containsObject:@"99999999"])
    {
        NSString *cate =[NSString stringWithFormat:@"%@",[[self.recommendDictionary  objectForKey:@"99999999"] objectForKey:@"next"]];
        if ([cate isEqualToString:@"cate"]) {
            
            NSString *cateid =[NSString stringWithFormat:@"%@",[[self.recommendDictionary  objectForKey:@"99999999"] objectForKey:@"next_id"]];
            NSString *catename =[NSString stringWithFormat:@"%@",[[self.recommendDictionary  objectForKey:@"99999999"] objectForKey:@"next_name"]];
            GoodClassViewController *cate =[[GoodClassViewController alloc] init];
            cate.cateName =catename;
            cate.cateCid =cateid;
            cate.cateTag =@"";
            [self.navigationController pushViewController:cate animated:YES];
            return;
        }
    }
    if (numArray.count>1) {
        NSString* kv =[numArray objectAtIndex:0];
        NSDictionary *dict = [self.recommendDictionary  objectForKey:kv];
        GoodClassViewController *cate =[[GoodClassViewController alloc] init];
        cate.cateName =[NSString stringWithFormat:@"%@",[dict objectForKey:@"cat2"]];
        cate.cateCid =[NSString stringWithFormat:@"%@",[dict objectForKey:@"cat2_id"]];
        cate.cateTag =@"";
        [self.navigationController pushViewController:cate animated:YES];
        return;
    }
    
}
-(void)commentMoreAction
{
    CommentViewController *comm =[[CommentViewController alloc] init];
    comm.photo_id =self.photo_id;
    comm.dictionary =self.dictionary;
    comm.fromType=@"1";
    [self.navigationController pushViewController:comm animated:YES];
    comm=nil;
}
-(void)handleSingleTapFrom
{
    CommentViewController *comm =[[CommentViewController alloc] init];
    comm.photo_id =self.photo_id;
    comm.dictionary =self.dictionary;
    comm.fromType=@"1";
    [self.navigationController pushViewController:comm animated:YES];
}
-(void)handleSingleTapFromRecommended
{
    GoodClassViewController *cate =[[GoodClassViewController alloc] init];
    cate.cateName =[NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"cat2"]];
    cate.cateCid =[NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"cat2_id"]];
    cate.cateTag =@"";
    [self.navigationController pushViewController:cate animated:YES];
}

-(void)commentAction
{
    CommentViewController *comm =[[CommentViewController alloc] init];
    comm.photo_id =self.photo_id;
    comm.fromType =@"1";
    comm.dictionary =self.dictionary;
    [self.navigationController pushViewController:comm animated:YES];
}
#pragma mark -----
-(void)getGoodDataWithPid:(NSString*)photo_id
{
    NSMutableDictionary *dict =[NSMutableDictionary dictionary];
    [dict setValue:photo_id forKey:@"photo_id"];
    [dict setValue:[NSString stringWithFormat:@"%d",self.currentPage] forKey:@"from"];
    __weak typeof (self) wSelf = self;
    self.isRequesting = YES;
    [BaseModel shaidanDetail:dict success:^(AFHTTPRequestOperation *operation, NSObject *result) {
        self.isRequesting = NO;
        [wSelf parserResultObject:result];
        [wSelf.tbView.infiniteScrollingView stopAnimating];
        [[ZToastManager ShardInstance] hideprogress];
        [ZShare hiddenAnimationView:wSelf.view];
    } failure:^(NSError *error) {
        [[ZToastManager ShardInstance] hideprogress];
        [wSelf.tbView.infiniteScrollingView stopAnimating];
        [ZShare hiddenAnimationView:wSelf.view];
    }];
    
}
-(void)refreshData
{
    [_nodeSectionArray removeAllObjects];
    _nodeSectionArray = [NSMutableArray arrayWithObjects:@"goodTitleCell",@"userinfo",@"photoCell",@"lovecell",@"detailCell",@"recommendcell",@"commentcell", nil];
    if (self.photo_id.length==0) {
        self.photo_id =[self.dictionary objectForKey:@"photo_id"];
    }
    NSString *sku_name =[[NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"title"]] replaceNullString];
    if (sku_name.length==0) {
      [self.nodeSectionArray removeObject:@"goodTitleCell"];
    }
    
    //
    self.currentPid =[self.dictionary objectForKey:@"brand_id"];
    //photo
    id photo =[self.dictionary objectForKey:@"detailPicURL"];
    if (photo && [photo isKindOfClass:[NSArray class]]) {
        [self.soldArray removeAllObjects];
        for (NSDictionary *str in photo) {
            [self.soldArray addObject:str];
        }
    }
    if ([self.soldArray count]==0) {
        [self.nodeSectionArray removeObject:@"photoCell"];
    }
    
    self.currentPage=0;
    
    NSDictionary *user = [self.dictionary objectForKey:@"user"];
    NSString *user_id =[[NSString stringWithFormat:@"%@",[user objectForKey:@"user_id"]] replaceNullString];
    NSString *suser_id = [[ZShare sharedInstance] getUserId];
    if ([user_id isEqualToString:suser_id] ){
        self.isShaidan = YES;
    }
    int like =[[self.dictionary objectForKey:@"like"] intValue];
    if (like==1) {
        self.footToolsView.isLove = YES;
    }else{
        self.footToolsView.isLove = NO;
    }
    NSString* reply_cnt =[[NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"reply_cnt"]] replaceNullString];
    if ([reply_cnt intValue]>0) {
        self.footToolsView.commentCount =reply_cnt;
    }
  
}
-(void)parserResultObject:(id)resultObject
{
    if (resultObject==nil) {
        return;
    }
    if (resultObject && [resultObject isKindOfClass:[NSDictionary class]]) {
        //
        
        id data =[resultObject objectForKey:@"data"];
        if (data && [data isKindOfClass:[NSDictionary class]]) {
            self.dictionary = data;
            [self refreshData];
        }
        //
        id ware =[resultObject objectForKey:@"ware"];
        if (ware && [ware isKindOfClass:[NSDictionary class]]) {
            self.shaidanDictionary = [NSMutableDictionary dictionaryWithDictionary:ware];
        }else
        {
            [self.shaidanDictionary removeAllObjects];
            [self.nodeSectionArray removeObject:@"detailCell"];
        }
        //
        //
        id lovelist =  [resultObject objectForKey:@"lovelist"];
        if (lovelist && [lovelist isKindOfClass:[NSArray class]]){
            [self.loveListArray removeAllObjects];
            [self.loveListArray addObjectsFromArray:lovelist];
            if ([self.loveListArray count]==0) {
                [self.nodeSectionArray removeObject:@"lovecell"];
            }
        }else{
            [self.nodeSectionArray removeObject:@"lovecell"];
        }
        //相关推荐
        id asking_list =  [resultObject objectForKey:@"asking_list"];
        if (asking_list && [asking_list isKindOfClass:[NSDictionary class]]){
            [self.askingDictionary addEntriesFromDictionary:asking_list];
            if (self.askingDictionary.count==1) {
                NSMutableArray *numArray = [NSMutableArray arrayWithArray:[self.askingDictionary allKeys]];
                if ([numArray containsObject:@"99999999"]) {
                    [self.nodeSectionArray removeObject:@"purchasecell"];
                }
            }
            if (self.askingDictionary.count==0) {
                [self.nodeSectionArray removeObject:@"purchasecell"];
            }
        }else
        {
            [self.askingDictionary removeAllObjects];
            [self.nodeSectionArray removeObject:@"purchasecell"];
        }
        
        //
        id comment_list =  [resultObject objectForKey:@"comment_list"];
        if (comment_list && [comment_list isKindOfClass:[NSArray class]]){
            if (self.currentPage==0) {
                [self.commentArray removeAllObjects];
            }
            [self.commentArray addObjectsFromArray:comment_list];
        }
        //相关推荐
        id recommend_list =  [resultObject objectForKey:@"recommend_list"];
        if (recommend_list && [recommend_list isKindOfClass:[NSDictionary class]]){
            [self.recommendDictionary addEntriesFromDictionary:recommend_list];
            if (self.recommendDictionary.count==1) {
                NSMutableArray *numArray = [NSMutableArray arrayWithArray:[self.recommendDictionary allKeys]];
                if ([numArray containsObject:@"99999999"]) {
                    [self.nodeSectionArray removeObject:@"recommendcell"];
                }
            }
            if (self.recommendDictionary.count==0) {
                [self.nodeSectionArray removeObject:@"recommendcell"];
            }
        }else
        {
            [self.recommendDictionary removeAllObjects];
            [self.nodeSectionArray removeObject:@"recommendcell"];
        }
        //
    
        //end
        BOOL isEnd =  [[resultObject objectForKey:@"end"] boolValue];
        if (isEnd) {
            [self.tbView.infiniteScrollingView stopAnimating];
            [self.tbView setShowsInfiniteScrolling:NO];
            NSString *end_msg =[resultObject objectForKey:@"end_msg"];
            self.tbView.tableFooterView =[ZShare footerView:end_msg];
        }
        
    }
    
    [_tbView reloadData];
    
}
//喜欢
-(void)likeWithPid:(NSString*)pid key:(NSString*)key indexPath:(NSIndexPath*)indexPath
{
    [UMengShare event:CK_LOVE acc:1];
    __weak typeof (self) wSelf = self;
    NSMutableDictionary *dict =[NSMutableDictionary dictionary];
    [dict setValue:pid forKey:@"photo_id"];
    [BaseModel love:dict success:^(AFHTTPRequestOperation *operation, id result) {
        int code =  [[result objectForKey:@"code"] intValue];
        NSString *like_cnt =  [NSString stringWithFormat:@"%@",[result objectForKey:@"like_cnt"]];
        if (code==1 || code==2) {
            if ([key isEqualToString:@"recommend"]) {
                
                NSMutableArray *numArray = [NSMutableArray arrayWithArray:[wSelf.recommendDictionary allKeys]];
                [numArray sortUsingComparator: ^NSComparisonResult (NSString *str1, NSString *str2) {
                    NSNumber *number1 = [NSNumber numberWithInteger:str1.floatValue];
                    NSNumber *number2 = [NSNumber numberWithInteger:str2.floatValue];
                    return [number1 compare:number2];
                }];
                if ([numArray containsObject:@"99999999"]) {
                    [numArray removeObject:@"99999999"];
                }
                for (int i=0; i<[numArray count]; i++) {
                    NSString *kv =[numArray objectAtIndex:i];
                    NSDictionary *dict =[wSelf.recommendDictionary objectForKey:kv];
                    NSString *pidd =[NSString stringWithFormat:@"%@",[dict objectForKey:@"photo_id"]];
                    if ([pidd isEqualToString:pid]) {
                        NSMutableDictionary *temp = [dict mutableCopy];
                        if (code==1) {
                            [temp setValue:@"1" forKey:@"like"];
                             _footToolsView.isLove =YES;
                        }else{
                            [temp setValue:@"0" forKey:@"like"];
                             _footToolsView.isLove =NO;
                        }
                        [temp setValue:like_cnt forKey:@"like_cnt"];
                        [wSelf.recommendDictionary setValue:temp forKey:kv];
                        
                        break;
                    }
                }
                [_tbView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
                
            }else if ([key isEqualToString:@"shaidan"])
            {
                NSMutableArray *numArray = [NSMutableArray arrayWithArray:[self.shaidanDictionary allKeys]];
                if ([numArray containsObject:@"99999999"]) {
                    [numArray removeObject:@"99999999"];
                }
                for (int i=0; i<[numArray count]; i++) {
                    NSString *kv =[numArray objectAtIndex:i];
                    NSDictionary *dict =[wSelf.shaidanDictionary objectForKey:kv];
                    NSString *pidd =[NSString stringWithFormat:@"%@",[dict objectForKey:@"photo_id"]];
                    if ([pidd isEqualToString:pid]) {
                        NSMutableDictionary *temp = [dict mutableCopy];
                        if (code==1) {
                            [temp setValue:@"1" forKey:@"like"];
                             _footToolsView.isLove =YES;
                        }else{
                            [temp setValue:@"0" forKey:@"like"];
                             _footToolsView.isLove =NO;
                        }
                        [temp setValue:like_cnt forKey:@"like_cnt"];
                        [wSelf.shaidanDictionary setValue:temp forKey:kv];
                        
                        break;
                    }
                }
                [_tbView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
                
            }else
            {
                NSMutableDictionary *temp = [wSelf.dictionary mutableCopy];
                if (code==1) {
                    [temp setValue:@"1" forKey:@"like"];
                    wSelf.footToolsView.isLove = YES;
                }else{
                    [temp setValue:@"0" forKey:@"like"];
                    wSelf.footToolsView.isLove = NO;
                }
                [temp setValue:like_cnt forKey:@"like_cnt"];
                wSelf.dictionary =temp;
            }
        }
        
    } failure:^(NSError *error) {
 //       [ZShare hiddenAnimationView:wSelf.view text:@""];
    }];
    
}
//顶踩
-(void)postTop:(NSString*)comment_id type:(int)type
{
    [UMengShare event:CK_TOP acc:1];
    NSMutableDictionary *dict =[NSMutableDictionary dictionary];
    if (type==1) {
        [dict setValue:@"push_top" forKey:@"action"];
    }else{
        [dict setValue:@"push_bottom" forKey:@"action"];
    }
    [dict setValue:comment_id forKey:@"comment_id"];
    [dict setValue:@"" forKey:@"good_id"];
    [dict setValue:@"" forKey:@"photo_id"];
    [dict setValue:@"" forKey:@"text"];
    
    __weak typeof (self) wSelf = self;
    [BaseModel comment:dict success:^(AFHTTPRequestOperation *operation, id result) {
        
        [[ZToastManager ShardInstance] showtoast:[result objectForKey:@"msg"]];
        [wSelf getGoodDataWithPid:wSelf.photo_id];
        
    } failure:^(NSError *error) {
        [[ZToastManager ShardInstance] showtoast:@"顶踩失败"];
        [ZShare hiddenAnimationView:wSelf.view text:@""];
    }];
    
}

-(void)likeAction
{
    NSString *pid =[NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"photo_id"]];
    if ([self isLogin]) {
        [self likeWithPid:pid key:@"likeAction" indexPath:nil];
    }
}
-(void)shareAction
{
    NSDictionary *share =[self.dictionary objectForKey:@"share"];
    [[ZPlatformShare sharedInstance] shareView:self.view dict:share];
}
-(void)shaidanAction
{
    NSString *pid =[NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"photo_id"]];
    if ([self isLogin]) {
        ShaiDanVC *shaidanVC =[[ShaiDanVC alloc] init];
        shaidanVC.type =2;
        shaidanVC.rank_id =pid;
        shaidanVC.cateDictionary = (NSMutableDictionary *)self.dictionary;
        [self.navigationController pushViewController:shaidanVC animated:YES];
        shaidanVC=nil;
    }
}
//更多评论
-(void)loadData
{
    NSMutableDictionary *dict =[NSMutableDictionary dictionary];
    [dict setValue:[NSString stringWithFormat:@"%d",self.currentPage] forKey:@"from"];
    [dict setValue:self.photo_id forKey:@"photo_id"];
    self.isRequesting =YES;
    __weak typeof (self) wSelf = self;
    wSelf.isRequesting = YES;
    [BaseModel commentList:dict success:^(AFHTTPRequestOperation *operation, NSObject *result) {
        [wSelf parserCommentResultObject:result];
        wSelf.isRequesting = NO;
        [_tbView.infiniteScrollingView stopAnimating];
        [[ZToastManager ShardInstance] hideprogress];
        [ZShare hiddenAnimationView:wSelf.view];
    } failure:^(NSError *error) {
        [_tbView.infiniteScrollingView stopAnimating];
        [[ZToastManager ShardInstance] hideprogress];
        wSelf.isRequesting = NO;
        [ZShare hiddenAnimationView:wSelf.view text:@""];
    }];
}

-(void)parserCommentResultObject:(id)resultObject
{
    if (resultObject==nil) {
        return;
    }
    if (resultObject && [resultObject isKindOfClass:[NSDictionary class]]) {
        
        id dataarray =[resultObject objectForKey:@"data"];
        if (dataarray && [dataarray isKindOfClass:[NSArray class]]) {
            if (self.currentPage == 0 && [dataarray count]>0) {
                [self.commentArray removeAllObjects];
            }
            for (id di in dataarray) {
                if (di && [di isKindOfClass:[NSDictionary class]])
                {
                    [self.commentArray addObject:di];
                }
            }
        }
        
        self.footToolsView.commentCount =[NSString stringWithFormat:@"%ld",self.commentArray.count];
        self.isLoadFinished =  [[resultObject objectForKey:@"end"] boolValue];
        if (self.isLoadFinished) {
            
            NSString *end_msg =[resultObject objectForKey:@"end_msg"];
            self.tbView.tableFooterView =[ZShare footerView:end_msg];
            
            [self.tbView.infiniteScrollingView stopAnimating];
            [self.tbView setShowsInfiniteScrolling:NO];
        }
    }
    
    [self.tbView reloadData];
    self.isRequesting = NO;
    
}
-(void)notificationManager
{
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(updateLoveList:)
                                                 name:@"updateCommentList"
                                               object:nil];
}
-(void)updateLoveList:(NSNotification*)notification
{
    DLog(@"%@",notification.object);
    self.currentPage = 0;
    [self getGoodDataWithPid:self.photo_id];
}
-(void)buyBtn
{
#ifdef LCB_GET_PRICE
    if (self.soldInfoDictionary) {
        int flag =[[self.soldInfoDictionary objectForKey:@"flag"] intValue];
        if (flag==0) {
            self.footToolsView.price=@"-1";
        }else{
            NSString *pristr =[[NSString stringWithFormat:@"%@",[self.soldInfoDictionary objectForKey:@"price_str"]] replaceNullString];
            self.footToolsView.price=pristr;
        }
    }else{
        self.footToolsView.price=@"-1";
    }
#endif
   
}
-(void)initFootView
{
    if (_footToolsView) {
        [_footToolsView removeFromSuperview];
        _footToolsView=nil;
    }
    _footToolsView = [[ZToolControl alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-BOTTOM_TOOLBAR_HEIGHT, self.view.frame.size.width, BOTTOM_TOOLBAR_HEIGHT)];
    __weak typeof (self) wSelf = self;
    [_footToolsView setCallBack:^(ZToolControlType type, UIView *v, id k, id va) {
        [wSelf foottercallback:type];
    }];
    [self.view addSubview:_footToolsView];
}
-(void)foottercallback:(ZToolControlType)type
{
    switch (type) {
        case ZToolControlType_comment:
        {
            if (self.isLogin) {
                [[CommentKeyBord commentKeyboard] textViewShowView:self commentKeyboardDelegate:self];
            }
          
            
        }
            break;
        case ZToolControlType_commentlist:
        {
            CommentViewController *comm =[[CommentViewController alloc] init];
            comm.photo_id =self.photo_id;
            comm.dictionary =self.dictionary;
            comm.fromType=@"0";
            [self.navigationController pushViewController:comm animated:YES];
        }
            break;
        case ZToolControlType_like:
        {
            if (self.isLogin) {
                [self likeAction];
            }
            
        }
            break;
        case ZToolControlType_buy:
        {
            NSString* strKeyword = [self.dictionary objectForKey:@"keywords"];
            if(strKeyword && [strKeyword isKindOfClass:[NSString class]])
            {
            }
            else
            {
                strKeyword = @"";
            }
            
            NiubiSearchVC *search =[[NiubiSearchVC alloc] init];
            search.strSearchTerm = strKeyword;//自动搜索 word
            [self.navigationController pushViewController:search animated:NO];

        }
            break;
            
        default:
            break;
    }
}
-(void)sendBtnClick:(UITextView *)textViewGet
{
//    NSLog(@"textViewGet.text=====>%@",textViewGet.text);
    if (textViewGet.text.length>0) {
        [self postComment:textViewGet.text];
    }
 
}
-(void)cancelBtnClick
{
    
}
-(void)postComment:(NSString*)txt
{
    NSMutableDictionary *dict =[NSMutableDictionary dictionary];
    [dict setValue:@"comment" forKey:@"action"];
    [dict setValue:@"" forKey:@"comment_id"];
    [dict setValue:self.photo_id forKey:@"photo_id"];
    [dict setValue:@"" forKey:@"good_id"];
    [dict setValue:txt forKey:@"text"];
    
    self.isRequesting =YES;
    __weak typeof (self) wSelf = self;
    wSelf.isRequesting = YES;
    [BaseModel comment:dict success:^(AFHTTPRequestOperation *operation, NSObject *result) {
        [wSelf commentResultObject:result];
    } failure:^(NSError *error) {
        [[ZToastManager ShardInstance] showtoast:@"点评失败"];
   //     [ZShare hiddenAnimationView:wSelf.view text:@""];
    }];
    
}

-(void)commentResultObject:(id)resultObject
{
    if (resultObject==nil) {
        return;
    }
    if (resultObject && [resultObject isKindOfClass:[NSDictionary class]]) {
        {
            self.currentPage =0;
            [self loadData];
        }
    }
    
    [_tbView reloadData];
}
@end
